package top.kaoshanji.p1ch12c;

/**
 * 代码清单-p1ch12c-117页c：代理类
 * @author kaoshanji
 * ^_^
 * create time 2025/3/22 18:11
 */
public class Proxy implements Subject {

    // 要实现哪个实现类
    private Subject subject = null;

    // 默认被代理者
    public Proxy() {
        this.subject = new Proxy();
    }

    // 通过构造函数传递被代理者
    public Proxy(Subject subject) {
        this.subject = subject;
    }

    @Override
    public void request() {

        this.before();
        this.subject.request();
        this.after();
    }

    // 预处理
    private void before() {}

    // 善后处理
    private void after() {}

}
